package com.aiyun.securiy.login.service;


import java.util.concurrent.Future;

import com.aiyun.securiy.login.security.SecurityUtils;
import com.aiyun.securiy.login.security.custom.CustomRequestFilter;
import lombok.extern.slf4j.Slf4j;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class AsyncService {


	@Async
	public void execute() throws InterruptedException {
		final String currentUser = SecurityUtils.getCurrentUser();
		log.info("current user is {}", currentUser);
		String currentUser1 = CustomRequestFilter.currentUser.get();
		log.info("CustomRequestFilter user is {}", currentUser1);
		Thread.sleep(10000);
		log.info("success");
	}

	@Async
	public Future<String> delay(int i) throws InterruptedException {
		log.info("process {}", i);
		Thread.sleep(3000);
		return new AsyncResult<>(i + "");
	}
}
